package com.geovis.emergency.spd.biz.app.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.geovis.emergency.spd.biz.app.mapper.SptTfsjMapper;
import com.geovis.emergency.spd.biz.app.service.SptTfsjFkbService;
import com.geovis.emergency.spd.biz.app.service.SptTfsjService;
import com.geovis.emergency.spd.biz.system.mapper.SystemFileBusinessMapper;
import com.geovis.emergency.spd.entity.app.dto.EventReportDto;
import com.geovis.emergency.spd.entity.app.dto.UnitInfoDto;
import com.geovis.emergency.spd.entity.app.entity.SptTfsj;
import com.geovis.emergency.spd.entity.app.entity.SptTfsjFkb;
import com.geovis.emergency.spd.entity.system.constant.SystemFileBusinessConstant;
import com.geovis.emergency.spd.entity.system.entity.SystemDept;
import com.geovis.emergency.spd.entity.system.entity.SystemFileBusiness;
import com.geovis.emergency.spd.entity.system.entity.SystemUser;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
@Slf4j
@DS("yjglyzt")
public class SptTfsjServiceImpl extends ServiceImpl<SptTfsjMapper, SptTfsj> implements SptTfsjService {

    private final SystemFileBusinessMapper systemFileBusinessMapper;

    private final SptTfsjFkbService sptTfsjFkbService;

    @Override
    public String reportEvent(SystemUser sendUser,SystemDept sendDept, SystemDept receiveDept, EventReportDto reportDto) {
        String time= reportDto.getReportDate().toString()+" 00:00:00";
        if("1".equals(reportDto.getBatchType()))
        {
            SptTfsj event=new SptTfsj();

            BeanUtils.copyProperties(reportDto,event);
            event.setHappenTime(time)
                    .setCreateTime(LocalDateTimeUtil.format(LocalDateTime.now(),"yyyy-MM-dd HH:mm:ss"))
                    .setSendTime(time)
                    .setReceiveDeptId(receiveDept.getId())
                    .setReceiveDeptTitle(receiveDept.getDeptName())
                    .setSendDeptId(sendDept.getId())
                    .setSendDeptTitle(sendDept.getDeptName())
                    .setRegionName(reportDto.getStreet())
                    .setSendUserName(sendUser.getRealName())
                    .setSignUserName(sendUser.getRealName());

            this.save(event);
            return event.getId();

        }
        SptTfsjFkb event=new SptTfsjFkb();
        BeanUtils.copyProperties(reportDto,event);
        event.setDisasterId(reportDto.getEventId());
        event.setCreateTime(LocalDateTimeUtil.format(LocalDateTime.now(),"yyyy-MM-dd HH:mm:ss"))
                .setSendTime(time)
                .setReceiveDeptId(receiveDept.getId())
                .setReceiveDeptTitle(receiveDept.getDeptName())
                .setSendDeptId(sendDept.getId())
                .setSendDeptTitle(sendDept.getDeptName())
                .setSignUserName(sendUser.getRealName());
        return event.getId();
    }
}
